package com.hgzy.sys.common;

import java.util.ArrayList;
import java.util.List;

/**
 * 构造左侧页面的菜单的层级结构
 * @author : look-word
 * @date : 2022-01-15 10:49
 **/
public class TreeNodeBuilder {

    public static List<TreeNode> build( List<TreeNode> treeNodes,Integer pid) {
        List<TreeNode> nodes = new ArrayList<TreeNode>();
        for (TreeNode n1 : treeNodes) {
            if (n1.getPid().equals(pid)){
                nodes.add(n1);
            }
            for (TreeNode n2 : treeNodes  ) {
                if (n1.getId().equals(n2.getPid())){
                    n1.getChildren().add(n2);
                }
            }

        }
        return nodes;
    }
}
